﻿@using DevExtreme.NETCore.Demos.Models.SampleData
@using Gantt = DevExtreme.NETCore.Demos.Models.Gantt

<div class="widget-container">
    <div class="options">
        <div class="caption">Options</div>
        <div class="option">
            @(Html.DevExtreme().CheckBox()
            .Value(true)
            .Text("Auto Update Parent Tasks")
            .OnValueChanged("ganttAutoUpdateParentTaskss_changed")
        )
        </div>
        <div class="option">
            @(Html.DevExtreme().CheckBox()
            .Value(true)
            .Text("Enable Dependency Validation")
            .OnValueChanged("ganttEnableDependencyValidation_changed")
        )
        </div>
    </div>
    @(Html.DevExtreme().Gantt<Gantt.Task>()
        .ID("gantt")
        .Validation(v => v.AutoUpdateParentTasks(true)
                        .ValidateDependencies(true))
        .Tasks(t => t
            .DataSource(ds => ds.Array().Data(SampleData.GanttTasksJohnsonResidence).Key("ID"))
            .KeyExpr("ID")
            .TitleExpr("Title")
            .ParentIdExpr("ParentId")
            .StartExpr("Start")
            .EndExpr("End")
            .ProgressExpr("Progress")
        )
        .Dependencies(d => d
            .DataSource(ds => ds.Array().Data(SampleData.GanttDependenciesJohnsonResidence).Key("ID"))
            .KeyExpr("ID")
            .PredecessorIdExpr("PredecessorId")
            .SuccessorIdExpr("SuccessorId")
            .TypeExpr("Type")
        )
        .Editing(e => e.Enabled(true))
        .Columns(columns => {
            columns.AddFor(m => m.Title)
                .Caption("Task")
                .Width(300);
            columns.AddFor(m => m.Start)
                .Caption("Start Date");
            columns.AddFor(m => m.End)
                .Caption("End Date");
        })
        .TaskListWidth(500)
        .TaskTitlePosition(GanttTaskTitlePosition.None)
    )
</div>

<script>
    function getGanttInstance() {
        return $("#gantt").dxGantt("instance");
    }

    function ganttAutoUpdateParentTaskss_changed(e) {
        var ganttInstance = getGanttInstance();
        ganttInstance.option("validation.autoUpdateParentTasks", e.value);
    }

    function ganttEnableDependencyValidation_changed(e) {
        var ganttInstance = getGanttInstance();
        ganttInstance.option("validation.validateDependencies", e.value);
    }
</script>
